package com.comment.Mapper;

import com.api.entity.CourseComment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CommentMapper extends BaseMapper<CourseComment> {

    List<CourseComment> getAllComment(@Param("id") int id,@Param("pageNum") int pageNum,@Param("pageSize") int pageSize);

    Integer getCourseAll(@Param("id") int id);

    @Insert("insert into course_comment(section_id,lesson_id,parent_id,user_name,course_id,comment,user_id,last_operator) values(0,0,0,#{userName},#{courseId},#{comment},#{userId},#{userId})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void addComment(CourseComment comment);

    @Insert("insert into course_comment_favorite(user_id,comment_id,is_del) values(#{userId},#{id},0)")
    void addCommentFavorite(CourseComment comment);

    @Update("update course_comment_favorite set is_del = 0 where user_id = #{userId} and comment_id = #{commentId}")
    void updateComment(Integer commentId, Integer userId);

    @Update("update course_comment_favorite set is_del = 1 where user_id = #{userId} and comment_id = #{commentId}")
    void updateCommentSave(Integer commentId, Integer userId);

    @Select("select like_count from course_comment where id = #{commentId}")
    Integer selectLikeCount(Integer commentId);

    @Update("update course_comment set like_count = #{i} where id = #{commentId}")
    void updateLikeCount(Integer i,Integer commentId);
}